Skip to content

fix: bundle transport fails when agent commits to HEAD instead of named branch#24317

Merged
pelikhan merged 4 commits intomainfrom
copilot/fix-javascript-unbloater-failure
Apr 3, 2026
Merged

fix: bundle transport fails when agent commits to HEAD instead of named branch#24317
pelikhan merged 4 commits intomainfrom
copilot/fix-javascript-unbloater-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

When the Copilot agent commits changes to the current checkout branch (HEAD) rather than first creating the target branch locally, the git bundle is created with ${GITHUB_SHA}..HEAD — bundling the checkout branch ref (e.g. refs/heads/copilot/make-bundle-default-patch-format) instead of the agent-requested ref (refs/heads/jsweep/clean-remove-trigger-label). create_pull_request.cjs then fails with fatal: couldn't find remote ref refs/heads/jsweep/clean-remove-trigger-label.

Changes

  • generate_git_bundle.cjs: In Strategy 2, before bundling ${GITHUB_SHA}..HEAD, create a local branch pointing to HEAD (git branch -f <branchName> HEAD) so the bundle always advertises refs/heads/<branchName>:

    - execGitSync(["bundle", "create", bundlePath, `${githubSha}..HEAD`], { cwd });
    + execGitSync(["branch", "-f", branchName, "HEAD"], { cwd });   // create the named ref
    + execGitSync(["bundle", "create", bundlePath, `${githubSha}..${branchName}`], { cwd });

Copilot AI linked an issue Apr 3, 2026 that may be closed by this pull request
… branch

In generate_git_bundle.cjs Strategy 2, when the agent-specified branch doesn't
exist locally, create a local branch pointing to HEAD before bundling so the
bundle contains refs/heads/<branchName> — which create_pull_request.cjs needs.

Also add a defensive fallback in create_pull_request.cjs that uses
git bundle list-heads to find available refs when the expected ref is missing.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/dc510197-23d5-4865-87e8-b6726dc060ea

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix workflow failure in JavaScript Unbloater fix: bundle transport fails when agent commits to HEAD instead of named branch Apr 3, 2026
Copilot AI requested a review from pelikhan April 3, 2026 14:14
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Apr 3, 2026

@copilot

remove fallback:

create_pull_request.cjs — defensive fallback: If the expected refs/heads/ ref is still absent from the bundle (any future edge case), run git bundle list-heads and use the first available refs/heads/* ref rather than failing immediately.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot

remove fallback:...

Done — removed the fallback in c6ba266.

@pelikhan pelikhan marked this pull request as ready for review April 3, 2026 14:38
Copilot AI review requested due to automatic review settings April 3, 2026 14:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes git bundle generation when the agent commits on the currently checked-out branch (HEAD) instead of first creating the requested local branch, ensuring the resulting bundle advertises the expected refs/heads/<branchName> ref so create_pull_request.cjs can fetch it reliably.

Changes:

  • In generate_git_bundle.cjs Strategy 2, create/force-update a local branch ref pointing at HEAD before bundling.
  • Bundle the commit range as ${GITHUB_SHA}..${branchName} (falling back to ${GITHUB_SHA}..HEAD if branch creation fails).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

try {
// Use -f (force) to overwrite any stale local branch from previous runs,
// since Strategy 1 verified the named branch does not exist as a proper local ref.
execGitSync(["branch", "-f", branchName, "HEAD"], { cwd });
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

branchName is user-/agent-controlled and may begin with "-". In git branch -f <branchName> HEAD, a leading dash can be parsed as another option (git requires -- to allow such branch names), which is both a correctness and hardening issue. Elsewhere you already defend against this (e.g., generate_git_patch.cjs uses -- when passing branch names to git fetch). Consider adding -- before branchName here (or using update-ref with an explicit refs/heads/... refname) so branch names can’t be interpreted as flags.

Suggested change
execGitSync(["branch", "-f", branchName, "HEAD"], { cwd });
// Use -- so a branch name beginning with "-" is not parsed as another option.
execGitSync(["branch", "-f", "--", branchName, "HEAD"], { cwd });

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Apr 3, 2026

@copilot

Review comments

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot

Review comments

Applied the review suggestion in 5cf8908 — added -- before branchName in git branch -f so branch names starting with - can't be misinterpreted as flags.

@pelikhan pelikhan merged commit e81c5e5 into main Apr 3, 2026
@pelikhan pelikhan deleted the copilot/fix-javascript-unbloater-failure branch April 3, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw] jsweep - JavaScript Unbloater failed

3 participants